﻿using System;
using System.Web.UI.WebControls;
using Core.Library;
using DataObject;
using DataObject.Category;
using DataObject.Product;

public partial class Controls_Common_Scroller : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            rptProduct.DataSource = ProductController.Product_ListTopHightlightProduct(SettingValues.PageSize_12);
            rptProduct.DataBind();
        }        
    }

    protected void rptProduct_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item)
        {
            var categoryId  = ConvertUtility.ToInt32(((HiddenField)e.Item.FindControl("hfCategoryId")).Value);
            var productId   = ConvertUtility.ToInt32(((HiddenField)e.Item.FindControl("hfProductId")).Value);
            var title       = ((HiddenField)e.Item.FindControl("hfTitle")).Value;

            var ltImage = (Literal)e.Item.FindControl("ltImage");

            var categoryName = CategoryController.GetCategoryName(categoryId);
            var pHref = UrlHelpers.ProductDetail(categoryName, ConvertUtility.ToInt32(productId), title);
            var imgHref = string.Format("{0}/Thumb.ashx?Id={1}&tId={2}&Size=190&Fix=highlight", Constants.ThumbImage, productId, (int)CategoryType.Product);

            ltImage.Text = string.Format("<center><a href=\"{0}\" title=\"{1}\" class=\"thumb\"><img src=\"{2}\" alt=\"\" /></a></center>", pHref, title, imgHref);
        }
    }
}